package com.qf.controller;

import com.qf.entity.Employee;
import com.qf.param.EmployeeAddOrUpdateParam;
import com.qf.service.EmployeeService;
import com.qf.utils.PageParam;
import com.qf.utils.PageVO;
import com.qf.utils.R;
import com.qf.vo.EmployeeListVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zdl
 * @date 2025/3/14
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    @GetMapping("/list")
    public R<PageVO<Employee>> list(PageParam pageParam) {
        PageVO<Employee> employeeList = employeeService.getEmployeeList(pageParam);
        return R.ok(employeeList);
    }

    @PostMapping("/add")
    public R<Integer> add(@RequestBody EmployeeAddOrUpdateParam employeeAddParam) {
        System.out.println("employeeAddParam:" + employeeAddParam);
        int i = employeeService.addEmployee(employeeAddParam);
        return R.ok(i);
    }

    @GetMapping("/download/excel")
    public R<?> downloadExcel(HttpServletResponse response) {
        employeeService.downloadExcel(response);
        return R.ok("导出成功");
    }

    @PostMapping("/del/{id}")
    public R<Integer> del(@PathVariable("id") int id) {
        int i = employeeService.delEmployeeById(id);
        return R.ok(i);
    }

    @PostMapping("/updateSave")
    public R<Integer> updateSave(@RequestBody EmployeeAddOrUpdateParam employeeUpdateParam) {
        int i = employeeService.updateSaveEmployee(employeeUpdateParam);
        return R.ok(i);
    }

    @GetMapping("/get")
    public R<Employee> get(int id) {
        System.out.println("id:" + id);
        Employee employeeListVO = employeeService.getEmployeeById(id);
        return R.ok(employeeListVO);
    }

    @PostMapping("/updateState")
    public R<Integer> updateState(@RequestBody EmployeeAddOrUpdateParam employeeUpdateParam) {
        int i = employeeService.updateState(employeeUpdateParam);
        return R.ok(i);
    }

    @GetMapping("/leader/list")
    public R<PageVO<Employee>> leaderList(PageParam pageParam) {
        PageVO<Employee> employeeList = employeeService.getEmployeeStateList(pageParam);
        return R.ok(employeeList);
    }

    @PostMapping("/leader/agree")
    public R<Integer> agree(@RequestBody Employee employee) {
        System.out.println("employee:" + employee);
        int i = employeeService.updateStateAgree(employee);
        return R.ok(i);
    }

    @PostMapping("/leader/noagree")
    public R<Integer> noagree(@RequestBody Employee employee) {
        System.out.println("employee:" + employee);
        int i = employeeService.updateStateNoAgree(employee);
        return R.ok(i);
    }

}
